package TokenRecognizer;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author jefoutta
 */
public class Node<E> {
    private E element;
    private Node<E> parent;
    private Node<E> leftChild;
    private Node<E> rightChild;
    private Node<E> centerChild;

    public Node(E e){
        leftChild = null;
        rightChild = null;
        centerChild = null;
        element = e;
    }

    public Node<E> getParent(){
        return parent;
    }

    public Node<E> getLeftChild(){
        return leftChild;
    }

    public Node<E> getRightChild(){
        return rightChild;
    }

    public Node<E> getCenterChild(){
        return centerChild;
    }

    public E getElement(){
        return element;
    }

    public Integer getChildSize(){
        Integer n = 0;
        
        if(rightChild != null)
            n++;
        if(leftChild != null)
            n++;
        if(centerChild != null)
            n++;
        
        return n;
    }

    public boolean hasChildren(){
        boolean b = false;
        if((rightChild != null)||(leftChild != null)||(centerChild != null))
            b = true;
        return b;
    }

    public void setLeftChild(Node<E> child){
        leftChild = child;
    }

    public void setRightChild(Node<E> child){
        rightChild = child;
    }

    public void setCenterChild(Node<E> child){
        centerChild = child;
    }

    public void setElement(E e){
        element = e;
    }

    public String toString(){
        String temp = "[";
        if((leftChild == null)&&(centerChild == null)&&(rightChild == null)){
            temp = temp = element + "]";
        }else{
        temp = temp + leftChild + ", ";
        temp = temp + centerChild + ", ";
        temp = temp + element + ", ";
        temp = temp + rightChild + "]";
        }
        return temp;
    }
}
